import { Body, Controller, Ip, Post } from '@nestjs/common';
import { CommonDto } from './dto/common';
import { LoginService } from './login.service';
import { ResponseUtilService } from '@app/response-util';
import LoginError from './error/LoginError';

@Controller('login')
export class LoginController {
    constructor(
        private readonly service:LoginService
    ) {}

    @Post()
    public async login(@Body() dto:CommonDto, @Ip() ip:string) {
        try {
            const r = await this.service.login(dto.account, dto.password, null, ip)

            return ResponseUtilService.successRes(r)

        } catch (error) {
            
            return ResponseUtilService.failRes(error.message, {code : error.code, data : error.count})
        }
    }
}
